﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class PatientDetailForm : Form
    {
        private Patient patient;
        private Button Cancel;
        private Button RemoveButt;
        private Button AddButt;
        private Button OKButt;
        private Label NameLable;
        private Label PatronymicLabel;
        private Label SurnameLabel;
        private Label DOBLabel;
        private Label DiagnoseLabel;
        private Label label6;
        private ListBox diagListBox;
        private DateTimePicker dateTimePicker1;
        private TextBox nameTextBox;
        private TextBox surnameTextBox;
        private TextBox diagDescrTextBox;
        private Label label5;
        private TextBox patronymicTextBox;

        public PatientDetailForm(Patient patient2)
        {
            InitializeComponent();
            patient = patient2;
            nameTextBox.Text = patient.patName;
            surnameTextBox.Text = patient.surname;
            patronymicTextBox.Text = patient.patronymic;
            dateTimePicker1.Value = patient.dob;
           

        }

        private void InitializeComponent()
        {
            this.Cancel = new System.Windows.Forms.Button();
            this.RemoveButt = new System.Windows.Forms.Button();
            this.AddButt = new System.Windows.Forms.Button();
            this.OKButt = new System.Windows.Forms.Button();
            this.NameLable = new System.Windows.Forms.Label();
            this.PatronymicLabel = new System.Windows.Forms.Label();
            this.SurnameLabel = new System.Windows.Forms.Label();
            this.DOBLabel = new System.Windows.Forms.Label();
            this.DiagnoseLabel = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.diagListBox = new System.Windows.Forms.ListBox();
            this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
            this.nameTextBox = new System.Windows.Forms.TextBox();
            this.surnameTextBox = new System.Windows.Forms.TextBox();
            this.patronymicTextBox = new System.Windows.Forms.TextBox();
            this.diagDescrTextBox = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // Cancel
            // 
            this.Cancel.Location = new System.Drawing.Point(388, 472);
            this.Cancel.Name = "Cancel";
            this.Cancel.Size = new System.Drawing.Size(75, 23);
            this.Cancel.TabIndex = 0;
            this.Cancel.Text = "CancelButt";
            this.Cancel.UseVisualStyleBackColor = true;
            this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
            // 
            // RemoveButt
            // 
            this.RemoveButt.Location = new System.Drawing.Point(264, 321);
            this.RemoveButt.Name = "RemoveButt";
            this.RemoveButt.Size = new System.Drawing.Size(75, 23);
            this.RemoveButt.TabIndex = 1;
            this.RemoveButt.Text = "Remove";
            this.RemoveButt.UseVisualStyleBackColor = true;
            this.RemoveButt.Click += new System.EventHandler(this.RemoveButt_Click);
            // 
            // AddButt
            // 
            this.AddButt.Location = new System.Drawing.Point(183, 321);
            this.AddButt.Name = "AddButt";
            this.AddButt.Size = new System.Drawing.Size(75, 23);
            this.AddButt.TabIndex = 2;
            this.AddButt.Text = "Add";
            this.AddButt.UseVisualStyleBackColor = true;
            this.AddButt.Click += new System.EventHandler(this.AddButt_Click);
            // 
            // OKButt
            // 
            this.OKButt.Location = new System.Drawing.Point(307, 472);
            this.OKButt.Name = "OKButt";
            this.OKButt.Size = new System.Drawing.Size(75, 23);
            this.OKButt.TabIndex = 3;
            this.OKButt.Text = "OK";
            this.OKButt.UseVisualStyleBackColor = true;
            this.OKButt.Click += new System.EventHandler(this.OKButt_Click);
            // 
            // NameLable
            // 
            this.NameLable.AutoSize = true;
            this.NameLable.Location = new System.Drawing.Point(48, 43);
            this.NameLable.Name = "NameLable";
            this.NameLable.Size = new System.Drawing.Size(35, 13);
            this.NameLable.TabIndex = 4;
            this.NameLable.Text = "Name";
            this.NameLable.Click += new System.EventHandler(this.NameLable_Click);
            // 
            // PatronymicLabel
            // 
            this.PatronymicLabel.AutoSize = true;
            this.PatronymicLabel.Location = new System.Drawing.Point(48, 133);
            this.PatronymicLabel.Name = "PatronymicLabel";
            this.PatronymicLabel.Size = new System.Drawing.Size(59, 13);
            this.PatronymicLabel.TabIndex = 5;
            this.PatronymicLabel.Text = "Patronymic";
            this.PatronymicLabel.Click += new System.EventHandler(this.PatronymicLabel_Click);
            // 
            // SurnameLabel
            // 
            this.SurnameLabel.AutoSize = true;
            this.SurnameLabel.Location = new System.Drawing.Point(48, 87);
            this.SurnameLabel.Name = "SurnameLabel";
            this.SurnameLabel.Size = new System.Drawing.Size(49, 13);
            this.SurnameLabel.TabIndex = 6;
            this.SurnameLabel.Text = "Surname";
            this.SurnameLabel.Click += new System.EventHandler(this.SurnameLabel_Click);
            // 
            // DOBLabel
            // 
            this.DOBLabel.AutoSize = true;
            this.DOBLabel.Location = new System.Drawing.Point(48, 178);
            this.DOBLabel.Name = "DOBLabel";
            this.DOBLabel.Size = new System.Drawing.Size(65, 13);
            this.DOBLabel.TabIndex = 7;
            this.DOBLabel.Text = "Date of birth";
            this.DOBLabel.Click += new System.EventHandler(this.DOBLabel_Click);
            // 
            // DiagnoseLabel
            // 
            this.DiagnoseLabel.AutoSize = true;
            this.DiagnoseLabel.Location = new System.Drawing.Point(48, 220);
            this.DiagnoseLabel.Name = "DiagnoseLabel";
            this.DiagnoseLabel.Size = new System.Drawing.Size(52, 13);
            this.DiagnoseLabel.TabIndex = 8;
            this.DiagnoseLabel.Text = "Diagnose";
            this.DiagnoseLabel.Click += new System.EventHandler(this.DiagnoseLabel_Click);
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(252, 279);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(0, 13);
            this.label6.TabIndex = 9;
            this.label6.Click += new System.EventHandler(this.label6_Click);
            // 
            // diagListBox
            // 
            this.diagListBox.FormattingEnabled = true;
            this.diagListBox.Location = new System.Drawing.Point(183, 220);
            this.diagListBox.Name = "diagListBox";
            this.diagListBox.Size = new System.Drawing.Size(280, 95);
            this.diagListBox.TabIndex = 10;
            this.diagListBox.SelectedIndexChanged += new System.EventHandler(this.diagListBox_SelectedIndexChanged);
            // 
            // dateTimePicker1
            // 
            this.dateTimePicker1.Location = new System.Drawing.Point(183, 178);
            this.dateTimePicker1.Name = "dateTimePicker1";
            this.dateTimePicker1.Size = new System.Drawing.Size(280, 20);
            this.dateTimePicker1.TabIndex = 11;
            this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
            // 
            // nameTextBox
            // 
            this.nameTextBox.Location = new System.Drawing.Point(183, 40);
            this.nameTextBox.Name = "nameTextBox";
            this.nameTextBox.Size = new System.Drawing.Size(272, 20);
            this.nameTextBox.TabIndex = 12;
            this.nameTextBox.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            // 
            // surnameTextBox
            // 
            this.surnameTextBox.Location = new System.Drawing.Point(183, 87);
            this.surnameTextBox.Name = "surnameTextBox";
            this.surnameTextBox.Size = new System.Drawing.Size(272, 20);
            this.surnameTextBox.TabIndex = 13;
            this.surnameTextBox.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
            // 
            // patronymicTextBox
            // 
            this.patronymicTextBox.Location = new System.Drawing.Point(183, 133);
            this.patronymicTextBox.Name = "patronymicTextBox";
            this.patronymicTextBox.Size = new System.Drawing.Size(272, 20);
            this.patronymicTextBox.TabIndex = 14;
            this.patronymicTextBox.TextChanged += new System.EventHandler(this.patronymicTextBox_TextChanged);
            // 
            // diagDescrTextBox
            // 
            this.diagDescrTextBox.Enabled = false;
            this.diagDescrTextBox.Location = new System.Drawing.Point(183, 361);
            this.diagDescrTextBox.Multiline = true;
            this.diagDescrTextBox.Name = "diagDescrTextBox";
            this.diagDescrTextBox.Size = new System.Drawing.Size(280, 105);
            this.diagDescrTextBox.TabIndex = 15;
            this.diagDescrTextBox.TextChanged += new System.EventHandler(this.diagDescrTextBox_TextChanged);
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(35, 361);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(109, 13);
            this.label5.TabIndex = 16;
            this.label5.Text = "Diagnose description:";
            this.label5.Click += new System.EventHandler(this.label5_Click);
            // 
            // PatientDetailForm
            // 
            this.ClientSize = new System.Drawing.Size(475, 507);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.diagDescrTextBox);
            this.Controls.Add(this.patronymicTextBox);
            this.Controls.Add(this.surnameTextBox);
            this.Controls.Add(this.nameTextBox);
            this.Controls.Add(this.dateTimePicker1);
            this.Controls.Add(this.diagListBox);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.DiagnoseLabel);
            this.Controls.Add(this.DOBLabel);
            this.Controls.Add(this.SurnameLabel);
            this.Controls.Add(this.PatronymicLabel);
            this.Controls.Add(this.NameLable);
            this.Controls.Add(this.OKButt);
            this.Controls.Add(this.AddButt);
            this.Controls.Add(this.RemoveButt);
            this.Controls.Add(this.Cancel);
            this.Name = "PatientDetailForm";
            this.Text = "PatientDetailForm";
            this.Load += new System.EventHandler(this.PatientDetailForm_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void PatientDetailForm_Load(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void OKButt_Click(object sender, EventArgs e)
        {
            patient.patName = nameTextBox.Text;
            patient.surname = surnameTextBox.Text;
            patient.patronymic = patronymicTextBox.Text;
            patient.dob = dateTimePicker1.Value;
            DialogResult = DialogResult.OK;
            Close();
        }

        private void AddButt_Click(object sender, EventArgs e)
        {

            List<Diagnose> diagList = DiagnoseDB.GetDiagnoses();
            SelectDiag selDiag = new SelectDiag(diagList);
            if (selDiag.ShowDialog() == DialogResult.OK)
            {
                if (!patient.patDiagnose.Contains(selDiag.GetSelectedItem().ID.Value))
                {
                    patient.patDiagnose.Add(selDiag.GetSelectedItem().ID.Value);
                }
            }
        }

        private void diagListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            List<Diagnose> diagList = DiagnoseDB.GetDiagnoses();
            string dName = diagListBox.SelectedItem.ToString();
            foreach (Diagnose el in diagList)
            {
                if (el.name == dName)
                {
                    diagDescrTextBox.Text = el.description;
                }
            }
        }

        private void diagDescrTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void RemoveButt_Click(object sender, EventArgs e)
        {
            /* int diagDel = diagListBox.SelectedIndex;
             diagListBox.Items.RemoveAt(diagListBox.SelectedIndex);*/
            List<Diagnose> diagList = DiagnoseDB.GetDiagnoses();
            string dName = diagListBox.SelectedItem.ToString();
            int? idToDel = -1;
            foreach (Diagnose el in diagList)
            {
                if (el.name == dName)
                {
                    idToDel = el.ID;
                }
            }
            Patient pat = new Patient();
            PatientDetailForm patDet = new PatientDetailForm(pat);
            // List<int> patDiagsDel = pat.patDiagnose;
            foreach (int el in pat.patDiagnose)
            {
                if (el == idToDel)
                {
                    pat.patDiagnose.Remove(el);
                }
            }
            PatientDB.EditedPatientToDB(pat);
            MessageBox.Show("Changes saved!");
            // PatientForm.SetDataToGrid();


        }

        private void NameLable_Click(object sender, EventArgs e)
        {

        }

        private void PatronymicLabel_Click(object sender, EventArgs e)
        {

        }

        private void SurnameLabel_Click(object sender, EventArgs e)
        {

        }

        private void DOBLabel_Click(object sender, EventArgs e)
        {

        }

        private void DiagnoseLabel_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void Cancel_Click(object sender, EventArgs e)
        {

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void patronymicTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }
    }
}
